package com.chen.dome2recursion;


import java.io.File;

public class deleteNullDir {
    public static void main(String[] args) {
        File dir = new File("");
        delete1(dir);
    }
    public static void delete1(File dir){
        if(!dir.exists()||!dir.isDirectory()||dir.isFile()) {
            return;
        }
        File[] files = dir.listFiles();
        if(files!=null&&files.length>0) {
            for (File f : files) {
                if(f.isDirectory()&&f.listFiles().length==0) {
                    f.delete();
                    System.out.println(f.getAbsolutePath()+"被删除");
                }else if(f.isFile()) {
                    break;
                } else if (f.isDirectory() && f.listFiles().length!=0) {
                    delete1(f);
                }
            }
        }

    }
}

